package org.dlsu.mt.parser.dictionary;
/**
 * made by LEFT thesis group
 *
 * monolingual dictionary module
 *
 * Word class
 * represents the structure of a word
 * contains the value of the word with all its corresponding word classes
 */

import java.util.Enumeration;
import java.util.Hashtable;

public class DictionaryWord
{
	private String value; //contains the value of the word
	private Hashtable<String, WordClass> classes;
	protected Hashtable posTags;
	
	/**
	 * the hashtable is used to store the word classes available to the word
	 * the value of the word is used as the key
	 */
	
	
	
	public DictionaryWord(String value)
	{
		/**
		 * constructor with one parameter in order to pass the value of the word
		 */
		this.value = value;
		classes = new Hashtable();
		posTags = new Hashtable();

	}
	
	public String getValue()
	{
		/**
		 * returns the value of the word
		 */
		return value;
	}
	
	public void addWordClass(WordClass w)
	{
		/**
		 * adds a word class to the word
		 */
		classes.put(w.getPOS(), w);
	}
	
	public boolean removeWordClass(String POS)
	{
		/**
		 * removes a word class from the word object
		 * returns true if remove is successful
		 * returns false otherwise
		 */
		if(classes.remove(POS)!=null)
			return true;
		else
			return false;
	}
	
	public boolean containsPOS(String POS)
	{
		/**
		 * checks if the certain part of speech is found in the word object
		 */
		return classes.containsKey(POS);
	}
	
	public WordClass getClass(String POS)
	{
		/**
		 * retrieves the WordClass object by specifying the part of speech
		 */
		return classes.get(POS);
	}
	
	public String[] getAllPOS()
	{
		/**
		 * retrieves all available part of speech in the word in the form of an array of strings
		 */ 
		Enumeration<String> e = classes.keys();
		String temp = null;
		String[] list = new String[classes.size()];
		int i=0;
		while(e.hasMoreElements())
		{
			temp = e.nextElement();
			list[i] = temp;
			i++;
		}
		return list;
	}
	
	
	public boolean updateWordClass(WordClass w)
	{
		/**
		 * replaces the word class of the same part of speech as the word class passed in the parameter
		 * if there is no word class with the specified part of speech in the word, there is no update done
		 *
		 * returns true if update is done on the word
		 * returns false otherwise
		 */
		if(classes.containsKey(w.getPOS()))
		{
			classes.remove(w.getPOS());
			classes.put(w.getPOS(), w);
			return true;
		}
		else
			return false;
	}
	
	public boolean mergeWordClass(WordClass w)
	{
		/**
		 * merges the word class passed in the parameter with the word class of the same part of speech that is found
		 * in the word
		 * merging will only be done if the specific part of speech is found in the word
		 *
		 * returns true if merging is done on the word
		 * returns false otherwise
		 */
		if(classes.containsKey(w.getPOS()))
		{
			classes.get(w.getPOS()).mergeWordClass(w);
			return true;
		}
		else
			return false;
	}
	
	
	public boolean mergeWord(DictionaryWord w)
	{
		/**
		 * merges the word with the word passed through the parameter if the values of both words are equal
		 * adds the word class if it is not found in the word, merges it otherwise
		 * if values of both words are not equal, merging is not performed
		 * 
		 *
		 * returns true if merging is done on the word
		 * returns false otherwise
		 */
		if(w.getValue().equals(value))
		{
			String[] POSList = w.getAllPOS();
			for(int i=0;i<POSList.length;i++)
			{
				String temp = POSList[i];
				if(containsPOS(temp))
				{
					mergeWordClass(w.getClass(temp));
				}
				else
				{
					addWordClass(w.getClass(temp));
				}
			}
			return true;
		}
		else
			return false;
	}
	
	
	public Object clone()
	{
		/**
		 * to be implemented in the future
		 */
		return null;
	}
	
	public String displayXML()
	{
		return null;
	}

	public Object interpret() throws Exception
	{
		return null;
	}

}